package 作业1022.zuoye1;

public class Market {
    String name;
    String address;
    Member m[] = new Member[100];
    int pos;

    public Market() {
        for (int i = 0; i < m.length; i++) {
            m[i] = new Member();
        }


    }

    public void show() {
        System.out.println("商场名称" + name);
        System.out.println("地址" + address);
        for (int i = 0; i < pos; i++) {
            if (m[i] == null) {
                break;
            } else {
                System.out.println("会员号" + m[i].membernum);
                System.out.println("姓名" + m[i].name);
                System.out.println("手机号" + m[i].phonenum);
                System.out.println("积分" + m[i].jifen);
            }
        }

    }

    public boolean add(Member me) {
        for (int i = 0; i < pos; i++) {
            if (m[i].membernum.equals(me.membernum)) {
                System.out.println("账号重复");
                return false;
            }
        }
        if (pos > m.length) {
            System.out.println("人员已满");
            return false;
        }
        m[pos++] = me;

        return true;
    }

    public boolean inc(String membernum, int jifen) {
        for (int i = 0; i < pos; i++) {
            if (m[i].membernum.equals(membernum)) {
                m[i].jifen += jifen;
            } else {
                System.out.println("账号不存在");
                return false;
            }
        }
        return true;
    }

    public String duihuan(String membernum, int choice) {

        for (int i = 0; i < pos; i++) {

            if (m[i].membernum.equals(membernum)) {

                switch ((choice)) {

                    case 1:

                        if (m[i].jifen >= 100) {

                            m[i].jifen -= 100;

                            System.out.println("兑换餐巾纸一包成功!");

                            return null;

                        }

                        System.out.println("积分不足！无法兑换");

                        return null;

                    case 2:

                        if (m[i].jifen >= 400) {

                            m[i].jifen -= 400;

                            System.out.println("积分不足！无法兑换!");

                            return null;

                        }

                        System.out.println("积分不足！无法兑换");

                        return null;

                    case 3:

                        if (m[i].jifen >= 1000) {

                            m[i].jifen -= 1000;

                            System.out.println("兑换炒锅一口成功!");

                            return null;

                        }

                        System.out.println("积分不足！无法兑换");

                        return null;

                    default:

                        System.out.println("输入错误!");

                        return null;

                }

            }

        }
        return null;
    }
}